package com.groupbaby.ydd.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
 * 一个工具类, 目的是获得总条数
 * 封装分页参数对象
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class GetPage implements Serializable {
    //总条数   当前页面    页大小    总条数    数据
    private Long count;
    private Long currentPage;
    private Long pageSize;
    private Long totalPage;
    private Object data;

    public static GetPage init(Long count, Long pageSize, Long currentPage, List data){

        long totalPage = count % pageSize == 0 ? count / pageSize : count / pageSize + 1;

        return new GetPage(count, pageSize, currentPage, totalPage, data);
    }
}
